package com.estar.app.business.mobileLogin.utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.estar.app.appsrvyyabx.mobile.domain.DataVO;
import com.estar.app.appsrvyyabx.mobile.domain.VOBase;
import com.estar.app.appsrvyyabx.mobile.domain.vo.CarVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.jyInfoVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.jyVO;
import com.estar.jinyou.entity.TmblEvalassistinfoEntity;
import com.estar.jinyou.entity.TmblEvallossinfoEntity;
import com.estar.jinyou.entity.TmblEvalpartinfoEntity;
import com.estar.jinyou.entity.TmblEvalrepairinfoEntity;
import com.estar.jinyou.vo.voEntity.EvalAssistInfoVO;
import com.estar.jinyou.vo.voEntity.EvalLossInfoVO;
import com.estar.jinyou.vo.voEntity.EvalPartInfoVO;
import com.estar.jinyou.vo.voEntity.EvalRepairInfoVO;
import com.estar.platform.caseInfo.entity.TmblCarInfoEntity;

@Component("jinYouUtil")
@Scope("prototype")
public class JinYouUtil {
	
	private static final Logger logger = Logger.getLogger(JinYouUtil.class);
	@Autowired
	private SystemService systemService;
	
	public DataVO getMess(DataVO dataVO){
		DataVO returnVo = new DataVO();
		try{
			jyVO jyvo=(jyVO) dataVO.getList().get(0);
			String indexName=jyvo.getIndexname();
			String reportNo=jyvo.getReportno();
			
			jyInfoVO jyinfo=new jyInfoVO();
			
			CriteriaQuery cq = new CriteriaQuery(TmblCarInfoEntity.class);
			cq.eq("reportNo", reportNo);
			cq.eq("indexNme", indexName);
			cq.add();
			List<TmblCarInfoEntity> carList=this.systemService.getListByCriteriaQuery(cq, false);
			
			TmblCarInfoEntity c=carList.get(0);
			CarVO cc =new CarVO();
			ObjCopyUtils.beansCopyFromJDBC(c, cc);
			jyinfo.setCarVO(cc);
			/*end==基本信息*/
			
			/*车辆基本信息 和 修理厂信息*/
			CriteriaQuery cq2 = new CriteriaQuery(TmblEvallossinfoEntity.class);
			cq2.eq("report", reportNo);
			cq2.eq("carindex", indexName);
			cq2.add();
			List<TmblEvallossinfoEntity> list=this.systemService.getListByCriteriaQuery(cq2, false);
			
			TmblEvallossinfoEntity lEntity=list.get(0);
			EvalLossInfoVO lossVo=new EvalLossInfoVO();
			ObjCopyUtils.beansCopyFromJDBC(lEntity, lossVo);
			
			
			/*end======车辆基本信息 和 修理厂信息*/
			
			/*配件信息*/
			CriteriaQuery cq3 = new CriteriaQuery(TmblEvalpartinfoEntity.class);
			cq3.eq("report", reportNo);
			cq3.eq("carindex", indexName);
			cq3.add();
			List<TmblEvalpartinfoEntity> partList=this.systemService.getListByCriteriaQuery(cq3, false);
			
			List<EvalPartInfoVO> evalPartInfoList=new ArrayList<EvalPartInfoVO>();
			if(partList.size()>0 && partList!=null){
				for(TmblEvalpartinfoEntity e:partList){
					EvalPartInfoVO ee =new EvalPartInfoVO();
					ObjCopyUtils.beansCopyFromJDBC(e, ee);
					evalPartInfoList.add(ee);
				}
				lossVo.setEvalPartInfoList(evalPartInfoList);
			}else{
				lossVo.setEvalPartInfoList(null);
			}
			
			/*end=====配件信息*/
			
			/*工时信息*/
			CriteriaQuery cq4 = new CriteriaQuery(TmblEvalrepairinfoEntity.class);
			cq4.eq("report", reportNo);
			cq4.eq("carindex", indexName);
			cq4.add();
			List<TmblEvalrepairinfoEntity> repairList=this.systemService.getListByCriteriaQuery(cq4, false);
			
			List<EvalRepairInfoVO> evalRepairList=new ArrayList<EvalRepairInfoVO>();
			if(repairList.size()>0 && repairList!=null){
				for(TmblEvalrepairinfoEntity r : repairList){
					EvalRepairInfoVO rr = new EvalRepairInfoVO();
					ObjCopyUtils.beansCopyFromJDBC(r, rr);
					evalRepairList.add(rr);
				}
				lossVo.setEvalRepairList(evalRepairList);
			}else {
				lossVo.setEvalRepairList(null);
			}
			/*end=====工时信息*/
			
			/*辅料信息*/
			CriteriaQuery cq5 = new CriteriaQuery(TmblEvalassistinfoEntity.class);
			cq5.eq("report", reportNo);
			cq5.eq("carindex", indexName);
			cq5.add();
			List<TmblEvalassistinfoEntity> assisList=this.systemService.getListByCriteriaQuery(cq5, false);
			
			List<EvalAssistInfoVO> evalAssitList=new ArrayList<EvalAssistInfoVO>();
			if(assisList.size()>0 && assisList!=null){
				for(TmblEvalassistinfoEntity as: assisList){
					EvalAssistInfoVO ass =new EvalAssistInfoVO();
					ObjCopyUtils.beansCopyFromJDBC(as, ass);
					evalAssitList.add(ass);
				}
				lossVo.setEvalAssitList(evalAssitList);
			}else {
				lossVo.setEvalAssitList(null);
			}
			/*end===辅料信息*/
			
			jyinfo.setLossInfoVO(lossVo);
			List<VOBase> jyInfoVOs=new ArrayList<VOBase>();
			jyInfoVOs.add(jyinfo);
			
			returnVo.setResultCde("1");
			returnVo.setMessage("信息查询成功");
			returnVo.setList(jyInfoVOs);
			
		}catch(Exception e){
			logger.error("查询精友详情系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("系统异常，获取失败");
		}
		
		
		return returnVo;
		
	}
}
